﻿package  
{
	
	import flash.display.MovieClip;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.events.MouseEvent;
	
	
	public class MsgUI extends MovieClip 
	{
		public var loadingCount:int = 0;
		public var timer:Timer = null;
		public var str:String = "";
		
		
		public function MsgUI() 
		{
			// constructor code
			
			timer = new Timer( 500 );
			timer.addEventListener( TimerEvent.TIMER , onTimer );
			timer.stop();
			
			okButton.addEventListener( MouseEvent.CLICK , onOK );
		}
		
		
		public function onOK( event:MouseEvent ):void
		{
			this.visible = false;
			timer.stop();
		}
		
		
		public function setText( s:String , l:Boolean = false ):void
		{
			str = s;
			txt.htmlText = s;
			
			okButton.visible = !l;
			
			if ( txt.textHeight > 30 )
			{
				txt.y = -35;
			}
			else
			{
				txt.y = -23;
			}
			
			loadingCount = 0;
			
			if ( l )
			{
				timer.start();
			}
			else
			{
				timer.stop();
			}
		}
		
		
		public function onTimer( event:TimerEvent ):void
		{
			loadingCount++;
			
			switch ( loadingCount )
			{
				case 0:
				txt.htmlText = str;
				break;
				case 1:
				txt.htmlText = str + ".";
				break;
				case 2:
				txt.htmlText = str + "..";
				break;
				case 3:
				txt.htmlText = str + "...";
				break;
			}
			
			if ( loadingCount == 3 )
			{
				loadingCount = 0;
			}
		}
		
		
	}
	
}
